package o;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class avd extends FilterInputStream {
    private static final short ॱ = ((short) ((int) ((Math.sqrt(5.0d) - 1.0d) * Math.pow(2.0d, 15.0d))));
    private int ʻ;
    private int ʼ;
    private int ʽ;
    private int[] ˊ = new int[8];
    private int ˊॱ;
    private int[] ˋ = new int[8];
    private int ˋॱ;
    private int[] ˎ = new int[8];
    private int ˏ = 8;
    private int ॱॱ;
    private int ᐝ;

    public avd(InputStream inputStream, int[] iArr, int i, byte[] bArr, int i2, int i3) throws IOException {
        super(inputStream);
        this.ʽ = Math.min(Math.max(i2, 5), 16);
        this.ʼ = i3;
        if (i3 == 3) {
            this.ˎ = ˎ(bArr);
        }
        ˊ(((((long) iArr[0]) & 4294967295L) << 32) | (((long) iArr[1]) & 4294967295L), i);
        this.ʻ = this.in.read();
    }

    public int read() throws IOException {
        ˊ();
        int[] iArr = this.ˊ;
        int i = this.ˏ;
        this.ˏ = i + 1;
        return iArr[i];
    }

    public int read(byte[] bArr, int i, int i2) throws IOException {
        if (i2 == 0) {
            return 0;
        }
        int read = read();
        if (read == -1) {
            return -1;
        }
        bArr[i] = (byte) read;
        read = 1;
        while (read < i2) {
            int read2 = read();
            if (read2 == -1) {
                return read;
            }
            bArr[i + read] = (byte) read2;
            read++;
        }
        return read;
    }

    public long skip(long j) throws IOException {
        long j2 = 0;
        while (j2 < j && read() != -1) {
            j2++;
        }
        return j2;
    }

    public int available() throws IOException {
        return 8 - this.ˏ;
    }

    public boolean markSupported() {
        return false;
    }

    private void ˊ(long j, int i) {
        if (i == 0) {
            ˏ(j);
            return;
        }
        this.ॱॱ = (int) j;
        this.ᐝ = ((int) j) * i;
        this.ˊॱ = ((int) j) ^ i;
        this.ˋॱ = (int) (j >> 32);
    }

    private void ˏ(long j) {
        this.ॱॱ = (int) j;
        this.ᐝ = (int) (((j >> 3) * ((long) ॱ)) >> 32);
        this.ˊॱ = (int) (j >> 32);
        this.ˋॱ = (int) ((j >> 3) + ((long) ॱ));
    }

    private void ॱ() {
        if (this.ʼ == 3) {
            System.arraycopy(this.ˊ, 0, this.ˋ, 0, this.ˊ.length);
        }
        int i = (this.ˊ[3] & 255) + ((((this.ˊ[0] << 24) & -16777216) + ((this.ˊ[1] << 16) & 16711680)) + ((this.ˊ[2] << 8) & 65280));
        int i2 = i;
        i = ((((this.ˊ[4] << 24) & -16777216) + ((this.ˊ[5] << 16) & 16711680)) + ((this.ˊ[6] << 8) & 65280)) + (this.ˊ[7] & 255);
        for (int i3 = 0; i3 < this.ʽ; i3++) {
            i -= (((ॱ * (this.ʽ - i3)) + i2) ^ ((i2 << 4) + this.ˊॱ)) ^ ((i2 >>> 5) + this.ˋॱ);
            i2 -= (((ॱ * (this.ʽ - i3)) + i) ^ ((i << 4) + this.ॱॱ)) ^ ((i >>> 5) + this.ᐝ);
        }
        this.ˊ[0] = i2 >>> 24;
        this.ˊ[1] = (i2 >> 16) & 255;
        this.ˊ[2] = (i2 >> 8) & 255;
        this.ˊ[3] = i2 & 255;
        this.ˊ[4] = i >>> 24;
        this.ˊ[5] = (i >> 16) & 255;
        this.ˊ[6] = (i >> 8) & 255;
        this.ˊ[7] = i & 255;
        if (this.ʼ == 3) {
            ˋ();
            System.arraycopy(this.ˋ, 0, this.ˎ, 0, this.ˋ.length);
        }
    }

    private void ˋ() {
        for (int i = 0; i < 8; i++) {
            int[] iArr = this.ˊ;
            iArr[i] = (iArr[i] ^ this.ˎ[i]) & 255;
        }
    }

    private int[] ˎ(byte[] bArr) {
        int length = bArr.length;
        int[] iArr = new int[length];
        for (int i = 0; i < length; i++) {
            iArr[i] = bArr[i] & 255;
        }
        return iArr;
    }

    private void ˊ() throws IOException {
        if (this.ˏ != 8) {
            return;
        }
        if (this.ʻ == -1) {
            Arrays.fill(this.ˊ, -1);
            this.ˏ = 0;
            return;
        }
        this.ˊ[0] = this.ʻ;
        for (int i = 1; i < 8; i++) {
            this.ˊ[i] = this.in.read();
        }
        ॱ();
        this.ʻ = this.in.read();
        if (this.ʻ == -1) {
            Arrays.fill(this.ˊ, 8 - this.ˊ[7], 8, -1);
        }
        this.ˏ = 0;
    }
}
